<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<input type="button" onclick="on()" value="点击我">
<input type="button" id="btn" value="再点击我">//推荐第二种

<script>
    function on() {
        alert("我被点击了");
    }

    document.getElementById("btn").onclick = function () {
        alert("我被点击了");
    }



</script>
</body>
</html>